﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business;
using Entity;
using System.Data;
using System.Data.SqlClient;

public partial class MayGiaCongChiTiet : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.HienDiaChi();
            this.HienBL();
            this.HienThiThongSoKiThuat();
            this.HienThiSPK();   
        }
    }
    void HienDiaChi()
    {
        string MaSP = Request.QueryString["MaSP"];
        
        ENhaCungCap NCC = new ENhaCungCap();
        NCC = BNhaCungCap.SelectByMaSP(MaSP);

        DataTable dt = new DataTable();
        dt.Columns.Add("MaNCC", typeof(string));
        dt.Columns.Add("TenNCC", typeof(string));
        dt.Columns.Add("DiaChi", typeof(string));
        dt.Columns.Add("Email", typeof(string));
        dt.Columns.Add("DienThoai", typeof(string));
        dt.Columns.Add("Website", typeof(string));
        dt.Columns.Add("BanDo", typeof(string));
        dt.Rows.Add(NCC.MaNCC, NCC.TenNCC, NCC.DiaChi, NCC.Email, NCC.DienThoai, NCC.Website,NCC.BanDo);

        GridView1.DataSource = dt;
        GridView1.DataBind();
        GridView2.DataSource = dt;
        GridView2.DataBind();
       
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        string MaSP = Request.QueryString["MaSP"];
        Random r = new Random();
        EPhanHoi eph = new EPhanHoi();
        eph.MaBL = r.Next().ToString();
        eph.MaSP = MaSP;
        eph.HoTen = txtHoTen.Text;
        eph.Email = txtEmail.Text;
        eph.NoiDung = txtNoiDung.Text;


        BPhanHoi.Insert(eph);
        txtHoTen.Text = "";
        txtEmail.Text = "";
        txtNoiDung.Text = "";

        HienBL();
    }

    void HienThiSPK()
    {
        

        string MaSP = Request.QueryString["MaSP"];

        ESanPham esp = BSanPham.SelectByID(MaSP);

        string loaiSP = esp.MaLSP;


        DataTable dt = BSanPham.SelectAll();

        int dem = 0;

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            var tempRow = dt.Rows[i];
            var temp = dt.Rows[i][1];
            if (!temp.Equals(loaiSP))
            {
                dt.Rows.Remove(tempRow);      //Update happen here
                dem++;
            }

        }


        xxx.Text = dem.ToString();
        
    }

    void HienThiThongSoKiThuat()
    {
        //lblChitiet
        string MaSP = Request.QueryString["MaSP"];
        ESanPham esp = new ESanPham();
        esp = BSanPham.SelectByID(MaSP);

        lblChiTiet.Text = esp.ChiTiet;

        
    }
    void HienBL()
    {
        DataTable dt = BPhanHoi.SelectAll();

        lbcount.Text = dt.Rows.Count.ToString();
        GridView3.DataSource = dt;
        GridView3.DataBind();
    }
}